﻿using Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Student
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            //初始化窗体的控件
            InitializeComponent();
        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            control_forms();//登录的函数
        }

        //private void select_T_Click(object sender, EventArgs e)//进入学生界面后点击选老师时进入的函数
        //{
        //    if (log_info.student.group_id==-1)//如果用户没有组队，弹框提示：
        //    {
        //        MessageBox.Show("操作之前请队长先输入队伍信息，提交队伍进行建队！");
        //        return;
        //    }

        //    if (log_info.student.is_gleader==-1)
        //    {
        //        MessageBox.Show("队长才能选择导师！");
        //        return;
        //    }

        //    select_teacher st_form = new select_teacher();
        //    st_form.ShowDialog();
        //}

        //private void GroupSetting_Click(object sender, EventArgs e)//进入学生界面后点击组队时进入的函数
        //{
        //    Group_setting group = new Group_setting();
        //    group.ShowDialog();//有疑问
        //}

        //private void logout_Click(object sender, EventArgs e)
        //{


        //    clear_controls();
        //    control_forms();
        //}

        private void control_forms()
        {
            this.Visible = false;////这行代码将主窗体的可见性设置为 false，即隐藏主窗体。这样做的目的是为了在登录过程中不显示主窗体。

            
            login frm_login = new login();
            if (frm_login.ShowDialog() == DialogResult.OK)//这行代码使用 ShowDialog 方法显示登录窗体。ShowDialog 方法会阻塞当前线程，直到对话框被关闭。如果用户成功登录并点击了“确定”按钮，ShowDialog 方法将返回 DialogResult.OK。
            {
                //更新主窗体上的控件，显示学生用户的信息：
                this.Visible = true;
                stu_name.Text = log_info.student.stu_name;
                phone.Text = log_info.student.phone;
                stu_no.Text = log_info.student.stu_no;
                if (log_info.stu_Group != null)//如果用户所属的组不为空，则更新与组相关的控件：
                {
                    project_name.Text = log_info.stu_Group.project_name;
                    totur.Text = log_info.stu_Group.teacher_name;
                }
            }
            else
                this.Close();//关闭主窗体
        }
        private void clear_controls()
        {
            stu_name.Text = "";
            phone.Text = "";
            stu_no.Text = "";
            project_name.Text = "";
            totur.Text = "";
            this.Visible = false;
            log_info.student = null;
            log_info.stu_Group = null;
        }

        private void uiTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void stu_name_TextChanged(object sender, EventArgs e)
        {

        }

        private void uiButton3_Click(object sender, EventArgs e)
        {
            clear_controls();
            control_forms();
        }

        private void uiButton1_Click(object sender, EventArgs e)//进入学生界面后点击组队时进入的函数
        {
            Group_setting group = new Group_setting();
            group.ShowDialog();//有疑问
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            if (log_info.student.group_id == -1)//如果用户没有组队，弹框提示：
            {
                MessageBox.Show("操作之前请队长先输入队伍信息，提交队伍进行建队！");
                return;
            }

            if (log_info.student.is_gleader == -1)
            {
                MessageBox.Show("队长才能选择导师！");
                return;
            }

            select_teacher st_form = new select_teacher();
            st_form.ShowDialog();
        }
    }
}
